<?php 

require_once ('includes/config.inc.php'); 

// Start output buffering:
ob_start();

// Initialize a session:
@session_start();


// Check for a $page_title value:
if (!isset($page_title)) {
	$page_title = 'Create New Campaign';
}

// If no first_name session variable exists, redirect the user:
if (!isset($_SESSION['first_name'])) {
	
	$url = BASE_URL . 'index.php'; // Define the URL.
	ob_end_clean(); // Delete the buffer.
	header("Location: $url");
	exit(); // Quit the script.
	
}

include ('includes/header.html');

if (isset($_POST['campaign'], $_POST['company']) ) {
	
		$errors = false;
		
		$campaign = $_POST['campaign'];
		$company = $_POST['company'];
		
		if ( !isset( $_POST['adtype'], $_POST['age'], $_POST['gender'], $_POST['ethnicity'], 
			$_POST['handset'], $_POST['interest'], $_POST['location'], $_POST['income'], $_POST['influenceScore']) ){
			$errors = true;
			echo '<p class="error">Please fill in all fields.</p>';
		}
		if ( empty($_POST['campaign']))
		{
			$errors = true;
			echo '<p class="error">Campaign Name must be entered.</p>';
		}
		
		if (empty($_POST['company']) ) {
			$errors = true;
			echo '<p class="error">Company Name must be entered.</p>';
		}
		
		if (! $errors)
		{
			$test = $_POST['location'];
			//finally, let's store our posted values in the session variables
			$_SESSION['campaign'] = $campaign;
			$_SESSION['company'] = $company;
			$_SESSION['adtype'] = $_POST['adtype'];
			$_SESSION['age'] = $_POST['age'];
			$_SESSION['gender'] = $_POST['gender'];
			$_SESSION['ethnicity'] = $_POST['ethnicity'];
			$_SESSION['handset'] = $_POST['handset'];
			$_SESSION['interest'] = $_POST['interest'];
			$_SESSION['location'] = $_POST['location'];
			$_SESSION['income'] = $_POST['income'];
			$_SESSION['influenceScore'] = $_POST['influenceScore'];
			

			header("Location: form2.php");		

			

		}
		
		
		
	}
		  
		  

?>

<h2>Please Specify Your Target Audience.</h2>
<form id="form1" name="form1" method="post" action="">
  <table width="100%" border="1" cellspacing="10" cellpadding="6">
    <tr>
      <td><label for="campaign">Campaign Name:</label></td>
      <td><input name="campaign" type="text" id="campaign" size="35" maxlength="40" /></td>
    </tr>
    <tr>
      <td><label for="company">Company Name:</label></td>
      <td><input name="company" type="text" id="company" size="35" maxlength="40" /></td>
    </tr>
    <tr>
      <td><label for="adtype">Advertisement Type:</label></td>
      <td><select name="adtype[]" size="4" multiple="multiple">
        <option value="1">SMS</option>
        <option value="2">MMS</option>
        <option value="4">Idle Screen</option>
        <option value="8">Banner</option>
      </select></td>
    </tr>
    <tr>
      <td><label for="age">Target Age Group(s)</label></td>
      <td><select name="age[]" size="5" multiple="multiple" id="age">
        <option value="1">Under 18</option>
        <option value="2">18-24</option>
        <option value="4">25-34</option>
        <option value="8">35-44</option>
        <option value="16">45-54</option>
        <option value="32">55-64</option>
        <option value="64">Over 65</option>
      </select></td>
    </tr>
    <tr>
      <td><label for="gender">Target Gender(s)</label></td>
      <td><select name="gender[]" size="2" multiple="multiple" id="gender">
        <option value="1">Male</option>
        <option value="2">Female</option>
      </select></td>
    </tr>
    <tr>
      <td><label for="ethnicity">Target Ethnicity Group(s)</label></td>
      <td><select name="ethnicity[]" size="6" multiple="multiple" id="ethnicity">
        <option value="16382" selected="selected">Any</option>
        <option value="2">Mixed Race</option>
        <option value="4">Arctic (Siberian, Eskimo)</option>
        <option value="8">Caucasian (European)</option>
        <option value="16">Caucasian (Indian)</option>
        <option value="32">Caucasian (Middle East)</option>
        <option value="64">Caucasian (North African, Other)</option>
        <option value="128">Indigenous Australian</option>
        <option value="256">Native American</option>
        <option value="512">North East Asian (Mongol, Tibetan, Korean Japanese, etc)</option>
        <option value="1024">Pacific (Polynesian, Micronesian, etc)</option>
        <option value="2048">South East Asian (Chinese, Thai, Malay, Filipino, etc)</option>
        <option value="4096">West African, Bushmen, Ethiopian</option>
        <option value="8192">Other Race</option>
      </select></td>
    </tr>
    <tr>
      <td><label for="handset">Handset Type(s)</label></td>
      <td><select name="handset[]" multiple="multiple" id="handset">
        <option value="1">SmartPhones</option>
        <option value="2">Non-SmartPhones</option>
      </select></td>
    </tr>
    <tr>
      <td><label for="interest">Interest(s)</label></td>
      <td><select name="interest[]" size="5" multiple="multiple" id="interest">
        <option value="1" selected="selected">Sports</option>
        <option value="2">Food</option>
        <option value="4">Technology</option>
        <option value="8">Health</option>
        <option value="16">Fashion</option>
      </select></td>
    </tr>
    <tr>
      <td><label for="location">Target Location(s)</label></td>
      <td><select name="location[]" size="7" multiple="multiple" id="location">
        <option value="1" selected="selected">Vancouver</option>
        <option value="2">Edmonton</option>
        <option value="4">Calgary</option>
        <option value="8">Winnipeg</option>
        <option value="16">Ottawa</option>
        <option value="32">Toronto</option>
        <option value="64">Montreal</option>
        <option value="128">Quebec City</option>
        <option value="256">Hamilton</option>
        <option value="512">Regina</option>
        <option value="1024">Victoria</option>
        <option value="2048">Saskatoon</option>
      </select></td>
    </tr>
    <tr>
      <td><label for="income">Target Income Range(s)</label></td>
      <td><select name="income[]" size="6" multiple="multiple" id="income">
        <option value="1">Under 20,000</option>
        <option value="2">20,000-30,000</option>
        <option value="4">30,000-40,000</option>
        <option value="8">40,000-50,000</option>
        <option value="16">50,000-75,000</option>
        <option value="32">75,000-100,000</option>
        <option value="64">100,000-150,000</option>
        <option value="128">Over 150,000</option>
      </select></td>
    </tr>
   <tr>
  	<td><label for="influenceScore">Minimum Influencial Score</label></td>
  	<td><select name="influenceScore" id="influenceScore">
  	  <option value="0">0</option>
  	  <option value="1">1</option>
  	  <option value="2">2</option>
  	  <option value="3">3</option>
  	  <option value="4">4</option>
  	  <option value="5" selected="selected">5</option>
  	  <option value="6">6</option>
  	  <option value="7">7</option>
  	  <option value="8">8</option>
  	  <option value="9">9</option>
  	  <option value="10">10</option>
    </select></td>
    </tr>
     <tr>
  	<td><input type="reset" name="reset" id="reset" value="Reset Form" /></td>
  	<td><input type="submit" name="submit" id="submit" value="Continue" /></td>
    </tr>
  </table>
</form>

<?php // Include the HTML footer file:
include ('includes/footer.html');
ob_end_flush();
?>
